import Vue from 'vue'
import Vuex from 'vuex'

// 导入home.js
import moduleHome from '@/vuex/home/home'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    token: sessionStorage.getItem('token'),
    menList: JSON.parse(sessionStorage.getItem('menList'))
  },
  // 改变state中属性的方法
  mutations: {
    setToken (state, key) {
      sessionStorage.setItem('token', key)
      state.token = key
    },
    clearToken (state) {
      sessionStorage.setItem('token', '')
      state.token = ''
    },
    setMenList (state, key) {
      sessionStorage.setItem('menList', JSON.stringify(key))
      state.menList = key
    },
    clearMenList (state) {
      sessionStorage.setItem('menList', '')
      state.menList = ''
    }
  },
  modules: {
    home: moduleHome
  }
})
export default store
